package com.jingbian.cppccbackend.controller.user;

import com.github.pagehelper.PageInfo;
import com.jingbian.cppccbackend.entity.ProposalSigners;
import com.jingbian.cppccbackend.entity.PublicOpinionSigners;
import com.jingbian.cppccbackend.entity.Result;
import com.jingbian.cppccbackend.entity.dto.PublicOpinionSignersListDTO;
import com.jingbian.cppccbackend.service.user.PublicOpinionSignersService;
import com.jingbian.cppccbackend.utils.ResultUtil;
import com.jingbian.cppccbackend.vo.PublicOpinionSignersListVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 社情民意联名人表 前端控制器
 * </p>
 */
@RestController
@RequestMapping("/users/publicOpinionSigners")
public class PublicOpinionSignersController {

    @Autowired
    private PublicOpinionSignersService publicOpinionSignersService;

    /**
     * 查询我的联名社情民意
     * @param publicOpinionSignersListDTO 查询参数
     * @return Result<PageInfo<PublicOpinionSignersListVO>>
     */
    @PostMapping("/list")
    public Result<PageInfo<PublicOpinionSignersListVO>> getList(
            @RequestBody PublicOpinionSignersListDTO publicOpinionSignersListDTO
    ) {
        return ResultUtil.success(publicOpinionSignersService.getList(publicOpinionSignersListDTO));
    }

    /**
     * 联名联名处理
     * @param status
     * @param opinionsId
     * @return Result<String>
     */
    @PutMapping("/change")
    public Result<PublicOpinionSigners> changeProposalSigners(@RequestParam Integer opinionsId, @RequestParam String status) {
        PublicOpinionSigners publicOpinionSigners = publicOpinionSignersService.changeStatus(opinionsId,status);
        return ResultUtil.success(publicOpinionSigners);
    }

    /**
     * 取消联名人未处理的社情民意
     * @param opinionId 社情民意id
     * @return Result<String>
     */
    @DeleteMapping("/deleteConsignOpinion/{opinionId}")
    public Result<String> deleteConsignOpinion(@PathVariable Integer opinionId) {
        Integer consign = publicOpinionSignersService.deleteConsignOpinion(opinionId);
        if(consign == 1) {
            return ResultUtil.fail("该报送不存在，无法取消。");
        } else if (consign == 2) {
            return ResultUtil.fail("非报送人，不可取消。");
        }else if(consign == 3) {
            return ResultUtil.fail("无法取消，联名人已确认");
        }else {
            return ResultUtil.success("报送取消成功！");
        }
    }

}
